package com.tang.common.exception;

import com.tang.common.exception.eumes.Error;
import com.tang.common.exception.eumes.Error.ErrorCodeMessage;
import lombok.Getter;

@Getter
public class BusinessException extends RuntimeException {

    private final ErrorCodeMessage errorCodeMessage;


    public BusinessException(ErrorCodeMessage errorCodeMessage) {
        super(errorCodeMessage.getMessage());
        this.errorCodeMessage = errorCodeMessage;
    }

    public BusinessException(Integer code, String message) {
        super(message);
        this.errorCodeMessage = Error.create(code, message);
    }

    public BusinessException(String message) {
        super(message);
        this.errorCodeMessage = Error.create(500, message);
    }


    public BusinessException(ErrorCodeMessage errorCodeMessage, Object... args) {
        super(String.format(errorCodeMessage.getMessage(), args));
        String message = String.format(errorCodeMessage.getMessage(), args);
        this.errorCodeMessage = Error.create(errorCodeMessage.getCode(), message);
    }

}
